<?php
/**
 * 恢复被清理的前端文件
 * 运行此脚本可以恢复所有被清理的文件
 */

$backupDir = __DIR__;
$frontendDir = __DIR__ . '/../../merchant';
$filesToRestore = array (
);

foreach ($filesToRestore as $file) {
    // 跳过特殊的 dist 清理标记
    if (strpos($file, 'dist/*') !== false) {
        // 恢复整个 dist 目录
        $distBackup = $backupDir . '/dist';
        $distTarget = $frontendDir . '/dist';
        
        if (is_dir($distBackup)) {
            $restoreCmd = "cp -r '$distBackup/'* '$distTarget/' 2>/dev/null";
            exec($restoreCmd, $output, $returnCode);
            if ($returnCode === 0) {
                echo "✅ 恢复 dist 目录完成\n";
            } else {
                echo "⚠️  dist 目录恢复失败\n";
            }
        }
        continue;
    }
    
    $sourcePath = $backupDir . '/' . $file;
    $targetPath = $frontendDir . '/' . $file;
    
    if (file_exists($sourcePath)) {
        // 创建目标目录
        $targetDir = dirname($targetPath);
        if (!is_dir($targetDir)) {
            mkdir($targetDir, 0755, true);
        }
        
        if (copy($sourcePath, $targetPath)) {
            echo "✅ 恢复成功: $file\n";
        } else {
            echo "❌ 恢复失败: $file\n";
        }
    } else {
        echo "⚠️  备份文件不存在: $file\n";
    }
}

echo "\n🎉 前端文件恢复完成！\n";
